<template>
	<view class="u-p-30">
		<u-form :model="form" ref="uForm"  :error-type="['toast']" :border-bottom="false">
			<u-form-item label="姓名" prop="name" required :border-bottom="false">
				<u-input v-model="form.name" placeholder="请输入姓名" />
			</u-form-item>
		</u-form>
		<u-button @click="submit" type="primary" class="btn u-m-t-30">提交</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				errorType:['toast'],
				form: {
					name: ''
				},
				rules: {
					name: [
						{ 
							required: true, 
							message: '请输入姓名',
							//type:'email',
							trigger: ['change','blur'],
						}
					]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
			this.form.name = this.dm_user.name;
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(async valid => {
					if (valid) {
						const params = {
							name:this.form.name
						}
					 
						await this.$u.api.updateInfo(params)
						const userInfo = await this.$u.api.userInfo()
						  
						this.$u.vuex("dm_user",userInfo);
						this.$u.toast("更新成功");
						setTimeout(()=>{
							this.$u.route({
								type:"reLaunch",
								url:"/pages/center/center"
							})
						},1000)
						 
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style scoped>
.btn{
	width: 70%;
}
</style>
